package hs4m.kidseducational.memory;

import hs4m.kidseducational.R;
import hs4m.kidseducational.R.layout;
import hs4m.kidseducational.R.menu;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.ImageButton;
import android.widget.Spinner;

public class MemoryLevelActivity extends Activity implements OnClickListener {

	ImageButton mCate1;
	ImageButton mCate2;
	ImageButton mCate3;
	Spinner mSpinLevel;
	int mLevel = 1;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_memory_level);

		// Initial
		mCate1 = (ImageButton) findViewById(R.id.cate01);
		mCate2 = (ImageButton) findViewById(R.id.cate02);
		mCate3 = (ImageButton) findViewById(R.id.cate03);

		mCate1.setOnClickListener(this);
		mCate2.setOnClickListener(this);
		mCate3.setOnClickListener(this);

		mSpinLevel = (Spinner) findViewById(R.id.Spinner01);
		ArrayAdapter adapter = ArrayAdapter.createFromResource(this,
				R.array.type, R.layout.spinner_text_center);
		adapter.setDropDownViewResource(R.layout.spinner_text_center); // android.R.layout.simple_spinner_dropdown_item
		mSpinLevel.setAdapter(adapter);

		// ArrayAdapter adapter = ArrayAdapter.createFromResource(this,
		// R.array.type, android.R.layout.simple_spinner_item);
		// adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		// mSpinLevel.setAdapter(adapter);
		mSpinLevel.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(android.widget.AdapterView<?> arg0,
					View arg1, int pos, long arg3) {

				// ((Spinner) findViewById(R.id.Spinner01)).setSelection(0);

				switch (pos) {
				case 0:
					mLevel = 1;
					break;
				case 1:
					mLevel = 2;
					break;
				case 2:
					mLevel = 3;
					break;
				case 3:
					mLevel = 4;
					break;
				case 4:
					mLevel = 5;
					break;
				default:
					mLevel = 1;
					return;
				}
			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {
				// TODO Auto-generated method stub

			}
		});
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.memory_level, menu);
		return true;
	}

	@Override
	public void onClick(View v) {
		Intent intent = new Intent(getApplicationContext(),
				MemoryActivity.class);
		switch (v.getId()) {
		case R.id.cate01:
			intent.putExtra("cate", 1);
			intent.putExtra("level", mLevel);
			startActivityForResult(intent, 1);
			break;
		case R.id.cate02:
			intent.putExtra("cate", 2);
			intent.putExtra("level", mLevel);
			startActivityForResult(intent, 1);
			break;
		case R.id.cate03:
			intent.putExtra("cate", 3);
			intent.putExtra("level", mLevel);
			startActivityForResult(intent, 1);
			break;
		case R.id.cate04:
			intent.putExtra("cate", 4);
			intent.putExtra("level", mLevel);
			startActivityForResult(intent, 1);
			break;
		case R.id.cate05:
			intent.putExtra("cate", 5);
			intent.putExtra("level", mLevel);
			startActivityForResult(intent, 1);
			break;
		default:
			break;
		}
	}

}
